package gis;

import cn.hutool.core.util.CoordinateUtil;
import cn.hutool.json.JSONUtil;

public class GeoTransformTools {
    public GeoTransformTools() {
    }

    public static CoordinateUtil.Coordinate cGCS2000transTo(CoordinateEnum targetCoordinate, double lon, double lat) {
        switch (targetCoordinate) {
            case CGCS2000:
                return new CoordinateUtil.Coordinate(lon, lat);
            case GCJ02:
                return CoordinateUtil.wgs84ToGcj02(lon, lat);
            case EPSG3857:
                return CoordinateUtil.wgs84ToMercator(lon, lat);
            case BD09:
                return CoordinateUtil.wgs84ToBd09(lon, lat);
            case GCJ023857:
                CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToGcj02(lon, lat);
                return CoordinateUtil.wgs84ToMercator(coordinate.getLng(), coordinate.getLat());
            default:
                throw new RuntimeException("暂不支持此种经纬度类型的转换!");
        }
    }

    public static CoordinateUtil.Coordinate transToCGCS2000(CoordinateEnum originCoordinate, double lon, double lat) {
        switch (originCoordinate) {
            case CGCS2000:
                return new CoordinateUtil.Coordinate(lon, lat);
            case GCJ02:
                return CoordinateUtil.gcj02ToWgs84(lon, lat);
            case EPSG3857:
                return CoordinateUtil.mercatorToWgs84(lon, lat);
            case BD09:
                return CoordinateUtil.bd09toWgs84(lon, lat);
            case GCJ023857:
                CoordinateUtil.Coordinate mercatorTogcj02 = CoordinateUtil.mercatorToWgs84(lon, lat);
                return CoordinateUtil.gcj02ToWgs84(mercatorTogcj02.getLng(), mercatorTogcj02.getLat());
            default:
                throw new RuntimeException("暂不支持此种经纬度类型的转换!");
        }
    }

    public static void main(String[] args) {
        CoordinateUtil.Coordinate coordinate = transToCGCS2000(CoordinateEnum.GCJ023857, 1.2750500241119403E7, 4584529.887412473);
        System.out.println("-->" + JSONUtil.toJsonStr(coordinate));
        System.out.println("-->" + String.format("%.9f", coordinate.getLng()));
    }
}
